<template>
  <div class="goods-list-item" @click="goodsItemClick">
    <img v-lazy="showImg" alt="" @load="imgLoad">
    <div class="goods-item-info">
      <p>{{ goods.title }}</p>
      <span class="price">¥{{ goods.price }}</span>
      <span class="collect"> {{ goods.cfav }}</span>
    </div>
  </div>
</template>

<script>
import {routerPath} from "@/common/constant";

export default {
  name: "GoodsListItem",
  props: {
    goods: {
      type: Object,
      default() {
        return {};
      }
    },
    imgLoadFunName: {
      type: String,
      default() {
        return "imgLoad";
      }
    }
  },
  computed: {
    showImg() {
      return this.goods.image || this.goods.img || this.goods.show.img;
    }
  },
  methods: {
    imgLoad() {
      this.$bus.$emit(this.imgLoadFunName);
    },
    goodsItemClick() {
      this.$router.push(routerPath.detail + "/" + this.goods.iid);
    }
  },
}
</script>

<style scoped>
.goods-list-item {
  width: 48%;
  margin-bottom: 15px;
}

.goods-list-item img {
  width: 100%;
  border-radius: 2%;
}

.goods-list-item .goods-item-info {
  font-size: 12px;
  text-align: center;
}

.goods-list-item .goods-item-info p {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 5px 0;
}

.goods-list-item .goods-item-info .price {
  color: var(--color-high-text);
  padding-right: 20px;
}

.goods-list-item .goods-item-info .collect {
  position: relative;
}

.goods-list-item .goods-item-info .collect::before {
  content: '';
  position: absolute;
  top: 0;
  left: -14px;
  width: 14px;
  height: 14px;
  background: url("~@/assets/img/common/collect.svg") no-repeat;
  background-size: 100%;
}
</style>